package itheima04;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import utils.C3P0Util;
import utils.JDBCUtil;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author xxx
 * @date 2021/1/5 19:46
 * @description
 */
public class Test {
    public static void main(String[] args) throws PropertyVetoException, SQLException {
        ComboPooledDataSource comboPooledDataSource=new ComboPooledDataSource();
        //D:\java349\day19\lib\mysql-connector-java-5.1.37-bin.jar!\com\mysql\jdbc\Driver.class
        comboPooledDataSource.setDriverClass("com.mysql.jdbc.Driver");
        comboPooledDataSource.setJdbcUrl("jdbc:mysal://localhost:3306/day19");
        comboPooledDataSource.setUser("root");
        comboPooledDataSource.setPassword("root");

        Connection connection=comboPooledDataSource.getConnection();
        System.out.println(connection);
    }
   @org.junit.Test
    public  void CP30() throws SQLException {
       Connection connection= C3P0Util.getConnection();
       String sql="select * from users where sid=?";

       PreparedStatement preparedStatement=connection.prepareStatement(sql);
       preparedStatement.setObject(1,2);
       ResultSet resultSet=preparedStatement.executeQuery();
       if(resultSet.next()){
           Object sid=resultSet.getString("sid");
           Object uname =resultSet.getObject("uname");
           Object upass=resultSet.getObject("upass");

           System.out.println("编号:"+sid+",用户名:"+uname+",密码:"+upass);
       }else {
           System.out.println("未查到数据");
       }

           C3P0Util.release(connection,preparedStatement,resultSet);
    }
}
